<template>
	<div name="limiteSignIn">
		<van-nav-bar
			:title="navBarTittle"
			left-arrow
			left-text="返回"
			fixed
			@click-left="$router.go(-1)"
		/>
        
        <div style="margin: 16px;">
            <van-button round type="info" @click="onSignIn" :disabled="btnDisable">签到</van-button>
        </div>
	</div>
</template>

<script>
	import {getLocation, longitude , latitude} from '@/api/gps.js';
	import { signInForStudent } from '@/api/signIn.js';
	import { Toast } from 'vant';
	export default {
        name: 'aKeySignIn',
		created() {
			getLocation();			
		},		
		data() {
			return {
				// signInTaskInfo: {},
				btnDisable: false,
				
			}
		},
		props: [
			'signInTaskInfo'
		],
		computed: {
			navBarTittle() {
                return "一键签到" 
            }
		},
		methods: {
			onSignIn() {
				const entity = {
					"latitude": latitude,
					"longitude": longitude,					
				}
				// this.signInTaskInfo = JSON.parse(localStorage.getItem('signInTaskInfo'));
				signInForStudent(this.signInTaskInfo.id , entity).then(res => {
					console.log(res);
					if(res.data.code === 0) {
						Toast('成功签到');
						this.btnDisable = true;
					} else {
						Toast('您已成功签到，请勿重复签到！');
					}
				}).catch(err => console.log(err));
			}
		}
	}
</script>

<style>
    
</style>